<html>
<head><meta charset="utf-8"><title>Try operator in destructure · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html">Try operator in destructure</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231564774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231564774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231564774">(Mar 24 2021 at 00:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="319552">Jeremiah Senkpiel</span> <a href="#narrow/stream/257204-project-error-handling/topic/Try.20operator.20in.20destructure/near/231564508">said</a>:</p>
<blockquote>
<p>Has there been any talk about allowing the Try (<code>?</code>) operator in a destructure position like this?</p>
<div class="codehilite"><pre><span></span><code>iter.inspect(|(_, thing)?|  { ... })
</code></pre></div>
<p>This could be quite handy when working with result-yielding iterators.</p>
</blockquote>
<p>_(Moved from <a class="stream" data-stream-id="257204" href="/#narrow/stream/257204-project-error-handling">#project-error-handling</a> )_</p>



<a name="231571962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231571962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231571962">(Mar 24 2021 at 02:06)</a>:</h4>
<p>there's some reluctance in allowing pattern matching to execute arbitrary user code like that. it also doesn't really match how patterns represent the "reverse" of an operation, e.g. how a <code>&amp;foo</code> pattern dereferences rather than references</p>



<a name="231576462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231576462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231576462">(Mar 24 2021 at 03:10)</a>:</h4>
<blockquote>
<p>reverse</p>
</blockquote>
<p><code>|¿(_, thing)| ..</code> ^^</p>



<a name="231587347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231587347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231587347">(Mar 24 2021 at 05:55)</a>:</h4>
<p>Ah yes the “Result-ify” operator</p>
<p>I suppose you could say this is the responsibility of the caller but with Iterator I’m not really sure how workable that is (I have no idea where discussions is at regarding some vague concept of falliable iterators beyond <code>collect&lt;Result&lt;&gt;&gt;</code>)</p>



<a name="231587357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231587357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231587357">(Mar 24 2021 at 05:55)</a>:</h4>
<p><span class="user-mention" data-user-id="310399">@Mara</span> Would that make <code>&amp;</code> the <code>fer</code> operator, and <code>&amp;mut</code> the <code>tumfer</code> operator?</p>



<a name="231587564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231587564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231587564">(Mar 24 2021 at 05:59)</a>:</h4>
<p>I’m not sure this counts as symmetry (and I don’t know that I care too much for symmetry), but <code>Try</code> is functionally similar to <code>TryFrom</code>, which seems to often(?) be the way to “undo” an enum wrapper without multiple branches</p>



<a name="231591280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231591280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231591280">(Mar 24 2021 at 07:03)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> string reversal? what is this, C? in Rust we have proper unicode support: ɟǝɹ / ʇnɯɟǝɹ</p>



<a name="231591521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231591521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231591521">(Mar 24 2021 at 07:06)</a>:</h4>
<p><span class="user-mention" data-user-id="319552">@Jeremiah Senkpiel</span> i'm not sure i understand what you mean. how are try and tryfrom similar?</p>



<a name="231650135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231650135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231650135">(Mar 24 2021 at 15:08)</a>:</h4>
<p>I definitely want <em>something</em> like this</p>



<a name="231705908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231705908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231705908">(Mar 24 2021 at 20:48)</a>:</h4>
<p><code>?</code> is similar to a conversion, is what I meant.</p>



<a name="231721346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231721346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231721346">(Mar 24 2021 at 22:44)</a>:</h4>
<p>Does the lack of symmetry to creating a structure from this proposed “try destructure” syntax present an impasse?</p>



<a name="231724953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231724953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231724953">(Mar 24 2021 at 23:21)</a>:</h4>
<p>I think it would be a sticking point, and I also think that you'd hit resistance about running user-provided code within patterns; this latter topic is something that the deref patterns proposal is working around (<a href="#narrow/stream/281601-project-deref-patterns">https://rust-lang.zulipchat.com/#narrow/stream/281601-project-deref-patterns</a>) and in your case would be enabled by the forthcoming Try trait reform (<a href="#narrow/stream/213817-t-lang/topic/try_trait_v2.3A.202nd.20attempt">https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/try_trait_v2.3A.202nd.20attempt</a>)</p>



<a name="231725146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231725146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231725146">(Mar 24 2021 at 23:23)</a>:</h4>
<p>the way the deref patterns proposal is working around it is to only allow the pattern for Deref types that are defined in the stdlib, so for minimal resistance you'd probably also want to limit yourself to only working on Try types defined in the stdlib. the syntax symmetry problem doesn't seem to have a clean workaround but if you had a slightly more concrete proposal with full code mockups then maybe something would present itself</p>



<a name="231797608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797608">(Mar 25 2021 at 13:13)</a>:</h4>
<p>hmm</p>



<a name="231797669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797669">(Mar 25 2021 at 13:14)</a>:</h4>
<p>conceptually what's happening in the deref case is that we're imagining a "pure" deref trait</p>



<a name="231797729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797729">(Mar 25 2021 at 13:14)</a>:</h4>
<p>that we are not defining right now (but it'd be good to be accumulating the constraints that deref patterns require)</p>



<a name="231797752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797752">(Mar 25 2021 at 13:14)</a>:</h4>
<p>this <em>probably</em> means said trait has to be unsafe</p>



<a name="231797785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797785">(Mar 25 2021 at 13:14)</a>:</h4>
<p>I guess one could imagine a pure try trait but .. hmm.</p>



<a name="231797793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797793">(Mar 25 2021 at 13:15)</a>:</h4>
<p>makes me wonder about making that trait unsafe</p>



<a name="231797800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797800">(Mar 25 2021 at 13:15)</a>:</h4>
<p>I'm not super thrilled about that</p>



<a name="231797819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797819">(Mar 25 2021 at 13:15)</a>:</h4>
<p>another option might be to limit where the <code>?</code> operator can be used</p>



<a name="231797876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797876">(Mar 25 2021 at 13:15)</a>:</h4>
<p>that is, applying the <code>?</code> in the "depths" of pattern matching is probably less common, right?</p>



<a name="231797922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797922">(Mar 25 2021 at 13:15)</a>:</h4>
<p>the most common place I've seen this come up is iterators that yield results</p>



<a name="231797994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231797994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231797994">(Mar 25 2021 at 13:16)</a>:</h4>
<p>instead of </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="231798002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231798002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231798002">(Mar 25 2021 at 13:16)</a>:</h4>
<p>one could imagine writing</p>



<a name="231798022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231798022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231798022">(Mar 25 2021 at 13:16)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="o">?</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="231798077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231798077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231798077">(Mar 25 2021 at 13:16)</a>:</h4>
<p>anyway I think <span class="user-mention" data-user-id="319552">@Jeremiah Senkpiel</span> it'd be good to dig a bit into the real use cases -- what is the <em>actual code</em> you expect to write? -- that might suggest the full range of options</p>



<a name="231798080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231798080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231798080">(Mar 25 2021 at 13:16)</a>:</h4>
<p>maybe create a hackmd?</p>



<a name="231822012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231822012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231822012">(Mar 25 2021 at 15:26)</a>:</h4>
<p>The <code>inspect</code> code I posted was something I tried to do in a real project.</p>
<p>Funny, I would have expected the loop to be:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="n">x</span><span class="o">?</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="231840520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840520">(Mar 25 2021 at 17:13)</a>:</h4>
<p><span class="user-mention" data-user-id="319552">@Jeremiah Senkpiel</span> yes, I think your notation is probably more correct, I was just pondering the idea of attaching the desugar not to the <em>pattern</em> but to the loop</p>



<a name="231840540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840540">(Mar 25 2021 at 17:13)</a>:</h4>
<p>you could also say that it is limited to the outermost pattern</p>



<a name="231840608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840608">(Mar 25 2021 at 17:14)</a>:</h4>
<p>my goal here is to say that you don't have to execute the Try operations <em>during pattern matching</em> but more as a kind of "prefix"</p>



<a name="231840647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840647">(Mar 25 2021 at 17:14)</a>:</h4>
<p>"before pattern matching begins, we apply the <code>?</code> operator to the value to be matched"</p>



<a name="231840694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840694">(Mar 25 2021 at 17:14)</a>:</h4>
<p>I imagine in a <code>match</code> context it would just be illegal -- only allowed in irrefutable pattern contexts</p>



<a name="231840720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840720">(Mar 25 2021 at 17:14)</a>:</h4>
<p>and only at the outermost level</p>



<a name="231840727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840727">(Mar 25 2021 at 17:14)</a>:</h4>
<p>I think that would be quite unintuitive, having it on the loop rather than attached to the value</p>



<a name="231840777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840777">(Mar 25 2021 at 17:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/231840540">said</a>:</p>
<blockquote>
<p>you could also say that it is limited to the outermost pattern</p>
</blockquote>
<p>agreed, hence this <span aria-label="point up" class="emoji emoji-1f446" role="img" title="point up">:point_up:</span></p>



<a name="231840789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840789">(Mar 25 2021 at 17:15)</a>:</h4>
<p>what I don't want is</p>



<a name="231840807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840807">(Mar 25 2021 at 17:15)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">x</span><span class="o">?</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="o">?</span><span class="p">)</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">foo</span><span class="w"></span>
</code></pre></div>



<a name="231840819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840819">(Mar 25 2021 at 17:15)</a>:</h4>
<p><em>although</em></p>



<a name="231840841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840841">(Mar 25 2021 at 17:15)</a>:</h4>
<p>in an irrefutable context, none of these problems apply</p>



<a name="231840871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840871">(Mar 25 2021 at 17:15)</a>:</h4>
<p>so maybe the answer is -- introduce <code>?</code> patterns, but allow them only in a limited range of cases</p>



<a name="231840888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840888">(Mar 25 2021 at 17:15)</a>:</h4>
<p>have to think about what exactly that range is, but we could start with irrefutable</p>



<a name="231840903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840903">(Mar 25 2021 at 17:15)</a>:</h4>
<p>meaning: <code>for</code> loop, closure arguments, <code>let</code> patterns</p>



<a name="231840913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840913">(Mar 25 2021 at 17:16)</a>:</h4>
<p>but not: <code>if let</code>, <code>match</code> arms</p>



<a name="231840949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840949">(Mar 25 2021 at 17:16)</a>:</h4>
<p>the latter are places where we are choosing between more than one option</p>



<a name="231840978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231840978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231840978">(Mar 25 2021 at 17:16)</a>:</h4>
<p>or, in those contexts, maybe they only apply at the outermost level for now</p>



<a name="231841036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841036">(Mar 25 2021 at 17:16)</a>:</h4>
<p>is what I'm saying making any sense, <span class="user-mention" data-user-id="319552">@Jeremiah Senkpiel</span> ? I'm trying to avoid having the <code>?</code> operator be evaluated in the midst of doing pattern matching, because that makes the order more observable</p>



<a name="231841056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841056">(Mar 25 2021 at 17:16)</a>:</h4>
<p>and introduces the possibility of weird side effects that we have to be careful about</p>



<a name="231841141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841141">(Mar 25 2021 at 17:17)</a>:</h4>
<p>consider like</p>



<a name="231841198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841198">(Mar 25 2021 at 17:17)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">match</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">Some</span><span class="p">(</span><span class="nb">Some</span><span class="p">(</span><span class="mi">22</span><span class="p">)</span><span class="o">?</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="w">    </span><span class="nb">Some</span><span class="p">(</span><span class="nb">Some</span><span class="p">(</span><span class="mi">23</span><span class="p">)</span><span class="o">?</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
</code></pre></div>



<a name="231841251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841251">(Mar 25 2021 at 17:18)</a>:</h4>
<p>actually</p>



<a name="231841258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841258">(Mar 25 2021 at 17:18)</a>:</h4>
<p>could we just limit to <em>bindings</em></p>



<a name="231841289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841289">(Mar 25 2021 at 17:18)</a>:</h4>
<p>nah, that's too limiting</p>



<a name="231841325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841325">(Mar 25 2021 at 17:18)</a>:</h4>
<p>anyway, the point is, we could permit the operator and just be restritive to avoid problematic cases, that's the high order bit. I'd be in favor of a project proposal along these lines myself.</p>



<a name="231841353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841353">(Mar 25 2021 at 17:19)</a>:</h4>
<p>/me stops typing</p>



<a name="231841533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841533">(Mar 25 2021 at 17:20)</a>:</h4>
<p>While I think that <code>(x?, y?)</code> is the natural progression from it but I think that's less valuable than <code>(_, y)?</code>. Consider the following:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="p">.</span><span class="n">inspect</span><span class="p">(</span><span class="o">|</span><span class="n">v</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="p">(</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">v</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Just for example, want to propagate try first</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">EnumType</span>::<span class="n">A</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">})</span><span class="w"></span>
</code></pre></div>
<p>vs inners</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="p">.</span><span class="n">inspect</span><span class="p">(</span><span class="o">|</span><span class="p">(</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">)</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Just for example, want to propagate try first</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">EnumType</span>::<span class="n">A</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="o">?</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">})</span><span class="w"></span>
</code></pre></div>



<a name="231841580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841580">(Mar 25 2021 at 17:20)</a>:</h4>
<p>I think we could support both without any problem</p>



<a name="231841594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841594">(Mar 25 2021 at 17:20)</a>:</h4>
<p>but I agree that <code>(_, y)?</code> is more important</p>



<a name="231841616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841616">(Mar 25 2021 at 17:20)</a>:</h4>
<p>The inners example is already, frankly, very straightforward with current syntax</p>



<a name="231841718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841718">(Mar 25 2021 at 17:21)</a>:</h4>
<p>The outers example isn't _bad_ but it could be better, especially with more complex types</p>



<a name="231841763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841763">(Mar 25 2021 at 17:21)</a>:</h4>
<p>do you know what I mean by "irrefutable context"?</p>



<a name="231841959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231841959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231841959">(Mar 25 2021 at 17:22)</a>:</h4>
<p>Do you mean only one possible variant of what <code>?</code> would have to operate on?</p>



<a name="231842010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842010">(Mar 25 2021 at 17:23)</a>:</h4>
<p>"irrefutable" means a pattern that cannot fail to match</p>



<a name="231842032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842032">(Mar 25 2021 at 17:23)</a>:</h4>
<p>(fail to match = "refute")</p>



<a name="231842040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842040">(Mar 25 2021 at 17:23)</a>:</h4>
<p>Ohhh I get it, yeah</p>



<a name="231842066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842066">(Mar 25 2021 at 17:23)</a>:</h4>
<p>this applies to <code>for pattern in ...</code>, closure arguments, <code>let pattern = ...</code></p>



<a name="231842091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842091">(Mar 25 2021 at 17:23)</a>:</h4>
<p>so what I'm saying is: there is no problem with <code>?</code> in those contexts</p>



<a name="231842118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842118">(Mar 25 2021 at 17:23)</a>:</h4>
<p>Because inside if a Try fails we're bailing out of a match in a weird way which could cause problems with destructure nesting</p>



<a name="231842125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842125">(Mar 25 2021 at 17:24)</a>:</h4>
<p>it would also apply to <code>match foo { pattern =&gt; }</code> (one arm)</p>



<a name="231842243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842243">(Mar 25 2021 at 17:24)</a>:</h4>
<p>right -- if there are multiple arms, it becomes a bit ambiguous sort of, at least in some positions --</p>



<a name="231842285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842285">(Mar 25 2021 at 17:24)</a>:</h4>
<p>I would be happy to start with irrefutable patterns</p>



<a name="231842314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842314">(Mar 25 2021 at 17:24)</a>:</h4>
<p>I think there are other places we could support in the future</p>



<a name="231842357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842357">(Mar 25 2021 at 17:25)</a>:</h4>
<p>Ideally it would be disallowed in <code>let pattern = ...</code>, because you can just put it at the end?</p>



<a name="231842361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842361">(Mar 25 2021 at 17:25)</a>:</h4>
<p>but irrefutable is by far the most common case where I have wanted this</p>



<a name="231842405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842405">(Mar 25 2021 at 17:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="319552">Jeremiah Senkpiel</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/231842357">said</a>:</p>
<blockquote>
<p>Ideally it would be disallowed in <code>let pattern = ...</code>, because you can just put it at the end?</p>
</blockquote>
<p>well, that depends</p>



<a name="231842415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842415">(Mar 25 2021 at 17:25)</a>:</h4>
<p>I might prefer for it to be allowed, perhaps we lint</p>



<a name="231842436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842436">(Mar 25 2021 at 17:25)</a>:</h4>
<p>but keep in mind that if we permit it anywhere in an irrefutable patern</p>



<a name="231842441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842441">(Mar 25 2021 at 17:25)</a>:</h4>
<p>you could do things like</p>



<a name="231842462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842462">(Mar 25 2021 at 17:25)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="p">(</span><span class="n">x</span><span class="o">?</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">z</span><span class="o">?</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="231842476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842476">(Mar 25 2021 at 17:26)</a>:</h4>
<p>and that can't trivially be done otherwise</p>



<a name="231842530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842530">(Mar 25 2021 at 17:26)</a>:</h4>
<p>admittedly I don't think I ever wanted to do it :)</p>



<a name="231842534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842534">(Mar 25 2021 at 17:26)</a>:</h4>
<p>but why not</p>



<a name="231842601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842601">(Mar 25 2021 at 17:26)</a>:</h4>
<p>I'd probably permit <code>let x? = foo</code> and if we are worried about TMWTDI, then lint for it and give a suggestion</p>



<a name="231842632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842632">(Mar 25 2021 at 17:26)</a>:</h4>
<p>just because I like things to work in a uniform way</p>



<a name="231842640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842640">(Mar 25 2021 at 17:26)</a>:</h4>
<p>Wait I thought that was refutable - is it only this which would be refutable?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="p">(</span><span class="n">x</span><span class="o">?</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">z</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="p">)</span><span class="o">?</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="231842660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842660">(Mar 25 2021 at 17:27)</a>:</h4>
<p>neither of those are refutable</p>



<a name="231842687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842687">(Mar 25 2021 at 17:27)</a>:</h4>
<p>a refutable pattern is like <code>Some(x)</code></p>



<a name="231842704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842704">(Mar 25 2021 at 17:27)</a>:</h4>
<p>because the <code>Option</code> may in fact be <code>None</code></p>



<a name="231842746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842746">(Mar 25 2021 at 17:27)</a>:</h4>
<p>I guess .. hmm .. so I'm stretching it here :)</p>



<a name="231842774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842774">(Mar 25 2021 at 17:27)</a>:</h4>
<p>admittedly when you put <code>?</code> inside the "irrefutable" pattern it becomes "refuable" in the sense that Try might fail</p>



<a name="231842791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842791">(Mar 25 2021 at 17:27)</a>:</h4>
<p>but there is no other source of dynamic testing</p>



<a name="231842805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842805">(Mar 25 2021 at 17:27)</a>:</h4>
<p>so we could just say "we test them left to right" in some defined order</p>



<a name="231842847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842847">(Mar 25 2021 at 17:28)</a>:</h4>
<p>and there is no real ambiguity or confusion about what happens</p>



<a name="231842876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842876">(Mar 25 2021 at 17:28)</a>:</h4>
<p>we should find a better name :)</p>



<a name="231842882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231842882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231842882">(Mar 25 2021 at 17:28)</a>:</h4>
<p>let's call it "single arm" patterns</p>



<a name="231843007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843007">(Mar 25 2021 at 17:29)</a>:</h4>
<p>Does that exclude this?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">?</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="231843069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843069">(Mar 25 2021 at 17:29)</a>:</h4>
<p>Or rather</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="o">|</span><span class="nb">Some</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">?|</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="231843130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843130">(Mar 25 2021 at 17:30)</a>:</h4>
<p>yes but those things are already illegal</p>



<a name="231843183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843183">(Mar 25 2021 at 17:30)</a>:</h4>
<p>(Option is a bad example here because of <code>transpose()</code>)</p>



<a name="231843204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843204">(Mar 25 2021 at 17:30)</a>:</h4>
<p>specifically because:</p>



<a name="231843219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843219">(Mar 25 2021 at 17:30)</a>:</h4>
<p>what do you do if the option is <code>None</code>?</p>



<a name="231843226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843226">(Mar 25 2021 at 17:30)</a>:</h4>
<p>(I'm ignoring <code>!</code> type here)</p>



<a name="231843251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843251">(Mar 25 2021 at 17:30)</a>:</h4>
<p><code>?</code> operator gives you an answer for that, so it's ok</p>



<a name="231843333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843333">(Mar 25 2021 at 17:31)</a>:</h4>
<p>Propagate <code>None</code> implicitly (Ok yes I know that's only possible with specifically <code>Option</code>)</p>



<a name="231843359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843359">(Mar 25 2021 at 17:31)</a>:</h4>
<p>well</p>



<a name="231843374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843374">(Mar 25 2021 at 17:31)</a>:</h4>
<p>if it's only at the topmost level, would it be possible to have this behavior be provided by new iterator combinators instead?</p>



<a name="231843382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843382">(Mar 25 2021 at 17:31)</a>:</h4>
<p>what type is <code>foo</code> here?</p>



<a name="231843396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843396">(Mar 25 2021 at 17:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="256342">bstrie</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/231843374">said</a>:</p>
<blockquote>
<p>if it's only at the topmost level, would it be possible to have this behavior be provided by new iterator combinators instead?</p>
</blockquote>
<p>no</p>



<a name="231843430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843430">(Mar 25 2021 at 17:31)</a>:</h4>
<p>well, sort of, but not in all positions</p>



<a name="231843452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843452">(Mar 25 2021 at 17:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="319552">Jeremiah Senkpiel</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/231587347">said</a>:</p>
<blockquote>
<p>...</p>
<p>I suppose you could say this is the responsibility of the caller but with Iterator I’m not really sure how workable that is (I have no idea where discussions is at regarding some vague concept of falliable iterators beyond <code>collect&lt;Result&lt;&gt;&gt;</code>)</p>
</blockquote>
<p>Maybe? But also, what I mentioned here above</p>



<a name="231843458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843458">(Mar 25 2021 at 17:32)</a>:</h4>
<p>also, it's counterintuitive</p>



<a name="231843553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843553">(Mar 25 2021 at 17:32)</a>:</h4>
<p>(in my view)</p>



<a name="231843594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843594">(Mar 25 2021 at 17:32)</a>:</h4>
<p>let's hold off on the "Do we want this" for a bit</p>



<a name="231843614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843614">(Mar 25 2021 at 17:32)</a>:</h4>
<p>I'd prefer to focus on the "how could we do it" for a bit</p>



<a name="231843636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843636">(Mar 25 2021 at 17:32)</a>:</h4>
<p>and then we can come back to "do we want it" :)</p>



<a name="231843656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843656">(Mar 25 2021 at 17:32)</a>:</h4>
<p>note though that I am not limiting it to top-level</p>



<a name="231843700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843700">(Mar 25 2021 at 17:33)</a>:</h4>
<p><span class="user-mention silent" data-user-id="319552">Jeremiah Senkpiel</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/231843333">said</a>:</p>
<blockquote>
<p>Propagate <code>None</code> implicitly (Ok yes I know that's only possible with specifically <code>Option</code>)</p>
</blockquote>
<p>so I feel like you are talking about <code>?</code> applied to <code>Option</code></p>



<a name="231843730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843730">(Mar 25 2021 at 17:33)</a>:</h4>
<p>but that is not what I am talking about</p>



<a name="231843748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843748">(Mar 25 2021 at 17:33)</a>:</h4>
<p>e.g., imagine that the type of <code>foo</code> is <code>Result&lt;Option&lt;T&gt;, E&gt;</code></p>



<a name="231843798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843798">(Mar 25 2021 at 17:33)</a>:</h4>
<p>then you could imagine <code>let Some(x)? = foo</code> but it wouldn't work because "what if the option is <code>None</code>"</p>



<a name="231843802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843802">(Mar 25 2021 at 17:33)</a>:</h4>
<p>but you could also do <code>let x?? = foo</code> and that <em>would</em> work</p>



<a name="231843859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843859">(Mar 25 2021 at 17:34)</a>:</h4>
<p>at least, presuming that you can <code>?</code> from both an option and a result in the same fn...</p>



<a name="231843912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231843912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231843912">(Mar 25 2021 at 17:34)</a>:</h4>
<p>maybe <code>foo: Option&lt;Option&lt;T&gt;&gt;</code> is a better example, same principles apply</p>



<a name="231844194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844194">(Mar 25 2021 at 17:36)</a>:</h4>
<p>I have yet to encounter a <code>??</code> and hope I don't have to, there's just compounding levels of confusion there, also, that becomes no longer irefutable, i think?</p>



<a name="231844246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844246">(Mar 25 2021 at 17:36)</a>:</h4>
<p>The point is not really about refutable vs irrefutable</p>



<a name="231844263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844263">(Mar 25 2021 at 17:36)</a>:</h4>
<p>Let's put that term aside</p>



<a name="231844308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844308">(Mar 25 2021 at 17:37)</a>:</h4>
<p>The point is more like "what happens if it doesn't match"</p>



<a name="231844322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844322">(Mar 25 2021 at 17:37)</a>:</h4>
<p>(Regarding that - I really hope <code>result.flatten()</code> is able to happen)</p>



<a name="231844343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844343">(Mar 25 2021 at 17:37)</a>:</h4>
<p>in the case of a <code>?</code> pattern, the answer is that it branches out to the enclosing scope, propagating the error</p>



<a name="231844371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844371">(Mar 25 2021 at 17:37)</a>:</h4>
<p>in the case of a <code>Some</code> pattern, it goes to the next arm</p>



<a name="231844389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844389">(Mar 25 2021 at 17:37)</a>:</h4>
<p>my point is that these are different in an important way :)</p>



<a name="231844407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844407">(Mar 25 2021 at 17:37)</a>:</h4>
<p>and that it means that we can accept <code>?</code> in positions that used to be only "truly irrefutable" patterns</p>



<a name="231844495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844495">(Mar 25 2021 at 17:38)</a>:</h4>
<p>so, it's not that you are likely to want to write <code>let x?? = foo</code></p>



<a name="231844507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844507">(Mar 25 2021 at 17:38)</a>:</h4>
<p>but more that the code has a single clear semantics</p>



<a name="231844573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844573">(Mar 25 2021 at 17:38)</a>:</h4>
<p>the compiler unwraps two options, propoagating any <code>None</code>, and otherwise you get the wrapped up value</p>



<a name="231844577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844577">(Mar 25 2021 at 17:38)</a>:</h4>
<p>there's nothing else it <em>could</em> do</p>



<a name="231844595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844595">(Mar 25 2021 at 17:39)</a>:</h4>
<p>but <code>let Some(Some(x)) = foo</code> is different</p>



<a name="231844619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844619">(Mar 25 2021 at 17:39)</a>:</h4>
<p>it's not clear what it should do if either option is <code>None</code></p>



<a name="231844756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844756">(Mar 25 2021 at 17:40)</a>:</h4>
<p>so in short I am arguing:</p>
<ul>
<li>In any context where there is a single variant in a match (for patterns, let bindings, matches, closure arguments) we can accept <code>?</code> patterns without any kind of hazard from observable side-effects and so forth.</li>
<li>In contexts with mutiple arms, we can put it off for now, but there are times we could accept it as well.</li>
</ul>



<a name="231844858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231844858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231844858">(Mar 25 2021 at 17:40)</a>:</h4>
<p>I am not (yet) arguing for the desirability or lack thereof of such a feature :)</p>



<a name="231845487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231845487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231845487">(Mar 25 2021 at 17:44)</a>:</h4>
<p>I stepped away for a minute and I think I agree that <code>??</code> could actually be reasonable in this context</p>



<a name="231845633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231845633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231845633">(Mar 25 2021 at 17:45)</a>:</h4>
<p>Would <code>|(t)??| {}</code> work in a context of say, <code>Result&lt;Option&lt;T&gt;&gt;</code>?</p>



<a name="231846116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231846116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231846116">(Mar 25 2021 at 17:48)</a>:</h4>
<p>Just to be clear, in your example, this would work today, yeah?:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="o">??</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="231846247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231846247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231846247">(Mar 25 2021 at 17:49)</a>:</h4>
<p>I suppose it's more likely that anyone writing it in that position would write <code>let x = foo.flatten()?</code>, but in the case of destructure, that is of course not possible.</p>



<a name="231847629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231847629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231847629">(Mar 25 2021 at 17:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="319552">Jeremiah Senkpiel</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/231845633">said</a>:</p>
<blockquote>
<p>Would <code>|(t)??| {}</code> work in a context of say, <code>Result&lt;Option&lt;T&gt;&gt;</code>?</p>
</blockquote>
<p>yes, so e.g. <code>|t??| t</code> would be like <code>Option&lt;Option&lt;T&gt;&gt; -&gt; Option&lt;T&gt;</code></p>



<a name="231848883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231848883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231848883">(Mar 25 2021 at 18:04)</a>:</h4>
<p>Are only enum matches refutable, or are there also other cases?</p>



<a name="231849011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231849011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231849011">(Mar 25 2021 at 18:05)</a>:</h4>
<p>constants</p>



<a name="231849020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231849020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231849020">(Mar 25 2021 at 18:05)</a>:</h4>
<p>e.g., <code>(x, 22)</code></p>



<a name="231856455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231856455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231856455">(Mar 25 2021 at 18:53)</a>:</h4>
<p>That's... new to me, where is that usable? Only in <code>match</code>-like things, right? Not in e.g. closure arguments surely?</p>



<a name="231862748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231862748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231862748">(Mar 25 2021 at 19:30)</a>:</h4>
<p><span class="user-mention" data-user-id="319552">@Jeremiah Senkpiel</span> Right, closure arguments must use irrefutable patterns. The only time you can use that in closure arguments is if there's only one value, so you <em>can</em> write <code>|(x, ())| x</code> for instance.</p>



<a name="231864881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231864881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231864881">(Mar 25 2021 at 19:45)</a>:</h4>
<p>Tiny bikeshed: could the question mark go before the binding? I find the syntax quite confusing when it goes after it (it looks too much like a value op):</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="o">?</span><span class="n">x</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="err">…</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="o">?</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">fallible</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">flatten</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">|??</span><span class="n">t</span><span class="o">|</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">t</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>It makes it clearer the binding happens after the try check passes</p>



<a name="231864994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231864994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231864994">(Mar 25 2021 at 19:46)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span>  Isn't that same thing as <code>|(x, _)| x</code>? That would only work with unit, right?</p>



<a name="231865104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231865104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231865104">(Mar 25 2021 at 19:46)</a>:</h4>
<p>I suspect that people, like me, would try to put it afterward naturally because that's how it is used elsewhere</p>



<a name="231865218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231865218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231865218">(Mar 25 2021 at 19:47)</a>:</h4>
<p>But perhaps that's a miss-assumption, not sure.</p>



<a name="231865760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231865760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231865760">(Mar 25 2021 at 19:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="319552">Jeremiah Senkpiel</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/231865104">said</a>:</p>
<blockquote>
<p>I suspect that people, like me, would try to put it afterward naturally because that's how it is used elsewhere</p>
</blockquote>
<p>Yeah, that could happen, but it's already the case with, for instance, <code>&amp;</code> in pattern <em>vs.</em> <code>&amp;</code> in an expression: part of learning Rust is realizing there is this duality in between expressions and patterns.<br>
On the other hand, fixing that "beginner's assumption" would be quite trivial for the compiler: it should just say that it is not a valid pattern, right before suggesting: <code>help: to use '?' in a pattern, put it before the variable name</code> <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="231866733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/231866733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#231866733">(Mar 25 2021 at 19:58)</a>:</h4>
<p>I could certainly live with <code>|?(x, _)| { x }</code>. I note that it is close to <code>tracing</code>'s <code>info!(?debug_print)</code> thing, but that probably doesn't matter much.</p>



<a name="232454226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232454226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232454226">(Mar 30 2021 at 16:21)</a>:</h4>
<p>I too would expect it to go afterwards</p>



<a name="232454306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232454306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232454306">(Mar 30 2021 at 16:22)</a>:</h4>
<p>I'm accustomed to patterns looking like expressions, I guess, although the analogy isn't exact here, since <code>x?</code> is not how you <em>construct</em> anything</p>



<a name="232454353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232454353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232454353">(Mar 30 2021 at 16:22)</a>:</h4>
<p><span class="user-mention" data-user-id="319552">@Jeremiah Senkpiel</span> are you interested in pursuing this design in particular? it seems to me that we reached a potentially useful pont -- if nothing else, I'd like to write-up a kind of design note on this</p>



<a name="232456675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232456675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232456675">(Mar 30 2021 at 16:36)</a>:</h4>
<p>What would be the next steps? Write a pre-rfc? I don't really have enough opinion to say whether the <code>?</code> should come before or after either, and I'm not sure how to elaborate at all on "how we'd teach this"</p>
<p>(This isn't the top feature request of mine so I'm a little hesitant to dedicate extra time to it before <code>let Some(x) = y else { }</code> patterns (whatever those are tentatively called? I forget), although this may be easier than that I guess?)</p>



<a name="232457096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232457096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232457096">(Mar 30 2021 at 16:39)</a>:</h4>
<p><span class="user-mention" data-user-id="319552">@Jeremiah Senkpiel</span> I think the next step would be a combination of two things: a project proposal if we want to move forward, and a revisiting of the "why" question that covers not just how this could be done but why this needs to have syntax rather than using the next best non-language-based alternative solution. The earlier discussion on this deferred the question of "why" in favor of "how", which was perfectly reasonable, but I think the "why" needs to be covered before moving forward.</p>



<a name="232457276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232457276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232457276">(Mar 30 2021 at 16:40)</a>:</h4>
<p>(To be clear, I'm not suggesting that it should or shouldn't move forward, but rather, any next step would need to include such justification, because it'll be needed when evaluating the project proposal.)</p>



<a name="232458551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232458551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232458551">(Mar 30 2021 at 16:49)</a>:</h4>
<p>Yeah, I wouldn't try to write a pre-RFC, I think a project proposal would be the next step. I could potentially help you to draft that. Maybe even draft it myself. I guess what I'm wondering is how much interest you have in "seeing this through". I don't have time to do it all myself but I have some potential interest, have to think about it.</p>



<a name="232459018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232459018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232459018">(Mar 30 2021 at 16:52)</a>:</h4>
<p>FWIW, I <em>personally</em> think there'd be value in having a mechanism like this. I'd certainly use it.</p>



<a name="232459584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232459584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232459584">(Mar 30 2021 at 16:55)</a>:</h4>
<p>I also think the most likely thing for this to get hung up on is the syntax bikeshed: postfix <code>?</code>, prefix <code>?</code>, keyword, postfix something on the iterator expression, etc.</p>



<a name="232460142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232460142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232460142">(Mar 30 2021 at 16:58)</a>:</h4>
<p>I also have a vague feeling that there may be generalizations we might want. If we had the ability for closures to return from their containing functions, that'd solve many problems (and potentially create new ones, but still).</p>



<a name="232520956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232520956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232520956">(Mar 31 2021 at 01:03)</a>:</h4>
<p>ooh, adding a try operator to patterns allows using:<code>for i? in result_returning_iter { ... }</code><br>
maybe we should also add <code>.await</code> to patterns!</p>



<a name="232528525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232528525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232528525">(Mar 31 2021 at 02:51)</a>:</h4>
<p>Hmmm, bringing up await here is a good point, I was assuming that would look more like JavaScript honestly, e.g.:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="k">await</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">async_iter</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Or</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">async</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">async_iter</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>But maybe it would be more idiomatic if it were like:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="k">await</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">async_iter</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>For what it’s worth, if that and “try” are desirable, I think they should adopt similar syntax.</p>



<a name="232624173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232624173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232624173">(Mar 31 2021 at 16:41)</a>:</h4>
<p>More musing:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="k">await</span><span class="w"> </span><span class="o">?</span><span class="n">x</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">async_result_iter</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>vs</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="k">await</span><span class="o">?</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">async_result_iter</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I think I generally like how rust has put "await" in a chaining position, but I think before reads much better in loop unrolls</p>



<a name="232624597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232624597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232624597">(Mar 31 2021 at 16:44)</a>:</h4>
<p>I assume making the syntax like the following example is ruled out, because the <code>try</code> word has a different meaning (e.g. try blocks):</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="k">await</span><span class="w"> </span><span class="kr">try</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">async_result_iter</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="232633560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232633560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232633560">(Mar 31 2021 at 17:37)</a>:</h4>
<p>The try block meaning might actually make that a <em>good</em> idea, IMO- I wrote about that idea a couple years ago: <a href="https://internals.rust-lang.org/t/for-await-loops/9819/7?u=rpjohnst">https://internals.rust-lang.org/t/for-await-loops/9819/7?u=rpjohnst</a></p>



<a name="232633943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232633943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232633943">(Mar 31 2021 at 17:39)</a>:</h4>
<p>the idea there being that in an expression, <code>?</code> and <code>.await</code> are "eliminators" of <code>Try</code> and <code>Future</code> types respectively, while <code>async {}</code> and <code>try {}</code> blocks are "constructors"- and the pattern/expression duality suggests using constructors in patterns to extract a value</p>



<a name="232647010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232647010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232647010">(Mar 31 2021 at 19:05)</a>:</h4>
<p>That's a reasonably compelling argument. I don't know about using <code>async</code> and <code>try</code> specifically, but I <em>do</em> feel like the problem with using <code>?</code> is that patterns should look like they're de-structuring the structure that's there, and <code>?</code> doesn't look like that. (Along the same lines, <code>&amp;</code> corresponds to <code>ref</code>. As a syllogism, I've been wondering "<code>&amp;</code> is to <code>ref</code> as <code>?</code> is to ...what".)</p>



<a name="232647107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232647107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232647107">(Mar 31 2021 at 19:05)</a>:</h4>
<p>FWIW, in some sense <code>for</code> is a destructuring mechanism as well; <code>for</code> destructures iterators into a loop.</p>



<a name="232648165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232648165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232648165">(Mar 31 2021 at 19:13)</a>:</h4>
<p>FWIW, <a href="https://github.com/rust-lang/C/issues/8">C#8</a> added <code>await foreach</code> (<a href="https://docs.microsoft.com/en-us/archive/msdn-magazine/2019/november/csharp-iterating-with-async-enumerables-in-csharp-8">https://docs.microsoft.com/en-us/archive/msdn-magazine/2019/november/csharp-iterating-with-async-enumerables-in-csharp-8</a>) and <code>await using</code> (<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/await#asynchronous-streams-and-disposables">https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/await#asynchronous-streams-and-disposables</a>), so it apparently chose to use the <em>elimination</em> operator for them.</p>



<a name="232648270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232648270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232648270">(Mar 31 2021 at 19:14)</a>:</h4>
<p>I don't know how to weigh the duality argument against the "you scan for <code>?</code> to find places that can propagate errors" argument.</p>



<a name="232648714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232648714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232648714">(Mar 31 2021 at 19:16)</a>:</h4>
<blockquote>
<p>you scan for <code>?</code> to find places that can propagate errors</p>
</blockquote>
<p>...and <code>return Err</code></p>



<a name="232648755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232648755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232648755">(Mar 31 2021 at 19:16)</a>:</h4>
<p>or <code>yeet</code> I suppose</p>



<a name="232654524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232654524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232654524">(Mar 31 2021 at 19:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/232647107">said</a>:</p>
<blockquote>
<p>FWIW, in some sense <code>for</code> is a destructuring mechanism as well; <code>for</code> destructures iterators into a loop.</p>
</blockquote>
<p>ye, i explored that a bit in the linked post as well</p>



<a name="232832446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232832446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232832446">(Apr 01 2021 at 22:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/232460142">said</a>:</p>
<blockquote>
<p>I also have a vague feeling that there may be generalizations we might want. If we had the ability for closures to return from their containing functions, that'd solve many problems (and potentially create new ones, but still).</p>
</blockquote>
<p>this feels like an unrelated problem?</p>



<a name="232832613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232832613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232832613">(Apr 01 2021 at 22:14)</a>:</h4>
<p>Hmm, <code>for try { x }</code> doesn't feel very compelling to me as a syntax, although I agree with the analogy. I think it's better to think of the <code>?</code> pattern as "transforming" the value being matched, though, and not so much as "destructuring it"</p>



<a name="232832620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232832620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232832620">(Apr 01 2021 at 22:14)</a>:</h4>
<p>this is why it can only appear in some locations</p>



<a name="232832649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232832649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232832649">(Apr 01 2021 at 22:15)</a>:</h4>
<p>put another way, the argument of "scan for <code>?</code> to find error propagation" feels really, really strong to me</p>



<a name="232832694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232832694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232832694">(Apr 01 2021 at 22:15)</a>:</h4>
<p>I would perhaps be ok with <code>for? x</code> and <code>for.await? x</code> though ; but in the pattern feels better</p>



<a name="232832707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232832707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232832707">(Apr 01 2021 at 22:15)</a>:</h4>
<p>I think <code>.await</code> and <code>?</code> are actually both the same kind of "transformation pattern"</p>



<a name="232832769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232832769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232832769">(Apr 01 2021 at 22:16)</a>:</h4>
<p>that you can only apply in irrefutable contexts</p>



<a name="232832808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232832808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232832808">(Apr 01 2021 at 22:16)</a>:</h4>
<p>I have to admit that <code>for x.await?</code>.. hmm ... is kind of weird :)</p>



<a name="232833885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232833885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232833885">(Apr 01 2021 at 22:28)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/232832446">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Try.20operator.20in.20destructure/near/232460142">said</a>:</p>
<blockquote>
<p>I also have a vague feeling that there may be generalizations we might want. If we had the ability for closures to return from their containing functions, that'd solve many problems (and potentially create new ones, but still).</p>
</blockquote>
<p>this feels like an unrelated problem?</p>
</blockquote>
<p>Not exactly. If we have the ability for closures to return from containing functions (call it <code>^?</code> for the sake of bikeshedding), then it's easy to write something like <code>.map(|x| x^?)</code>.</p>



<a name="232833966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/232833966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#232833966">(Apr 01 2021 at 22:28)</a>:</h4>
<p>Which I find more self-explanatory than <code>for?</code> or <code>for x? in</code>.</p>



<a name="233409415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Try%20operator%20in%20destructure/near/233409415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Try.20operator.20in.20destructure.html#233409415">(Apr 06 2021 at 23:58)</a>:</h4>
<p>I see.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>